<?php
/**
 * 车主模块逻辑层
 */
namespace AuctionBack\Logic;

use AuctionBack\Model\CarOwnerModel;

class CarOwnerLogic
{

    Protected $autoCheckFields = false;

    /**
     * 车主id
     */
    private $owner_id;

    /**
     * 构造,初始化"车主id"
     */
    public function __construct($owner_id)
    {
        $this->owner_id = $owner_id;
    }


    /**
     * 按照查询条件查询车主的信息(多条)
     *
     * @param $data
     * @return mixed
     */
    public static function getCarOwnerInfo($data)
    {
        return D('CarOwner', 'Model')->field('owner_id')->where($data)->select();
    }

    /**
     * 按照查询条件查询车主的信息(单条)
     *
     * @param array $data 查询条件
     * @return mixed
     */
    public static function getCarOwnerByMap($data)
    {
        return D('CarOwner', 'Model')->where($data)->find();
    }

    /**
     * 根据手机号获得最近一条车主信息
     *
     * @param string $phone
     *
     * @return array
     */
    public function getCarOwnerInfoByPhone($phone = '')
    {
        if (empty($phone)) {
            return false;
        }
        $condition['phone'] = ['eq', $phone];
        $order = 'owner_id DESC';
        return D('CarOwner', 'Model')->where($condition)->order($order)->find();
    }

    /**
     * 更新车主表
     *
     * @param array $data
     *
     * @return bool
     */
    public function updateCarOwnerInfo($data = [])
    {
        if (empty($data) || empty($data['owner_id'])) {
            return false;
        }
        return D('CarOwner', 'Model')->save($data);
    }

    /**
     * 获取线索详情
     * @return mixed
     */
    public function detail()
    {
        return D('CarOwner', 'Model')->where("owner_id='{$this->owner_id}'")->find();
    }
}